<!-- 提现 -->
<template>
	<view>
		<u-navbar :isFixed="true" title="提现" :borderBottom="false"></u-navbar>
		<view class="block"></view>
		<view class="wrap">
			<view class="item flex_bet_align">
				<view class="name">账户余额</view>
				<view class="count">￥{{wallet.countBalance?wallet.countBalance:0}}</view>
			</view>
			<view class="item flex_bet_align">
				<view class="name">可提现余额</view>
				<view class="count">￥{{wallet.availableBalance}}</view>
			</view>
			<view class="item flex_bet_align">
				<view class="name">提现金额</view>
				<!-- @input="checkNum" :maxlength="maxlength" -->
				<input type="digit" v-model="withdrawal_money" placeholder="请输入提现金额">
			</view>
			<view class="item flex_bet_align">
				<view class="name">手续费<text>第三方手续费</text></view>
				<view class="count" v-if="withdrawal_money">￥{{(withdrawal_money*wallet.commission)/100}}</view>
				<view class="count" v-else>提现比例{{wallet.commission}}%</view>
			</view>
			<view class="item flex_bet_align">
				<view class="name"><text>最小提现金额：{{wallet.withdrawaMinPrice}}</text></view>
				<view class="name"><text>最大提现金额：{{wallet.withdrawalMaxPrice}}</text></view>
			</view>
			<view class="item flex_bet_align">
				<view class="name"><text>每月提现{{wallet.withdrawNumber}}次</text></view>
			</view>
			<view class="item flex_bet_align">
				<view class="name"><text>提现说明：{{wallet.withdrawDesc}}</text></view>
			</view>
			<view class="block"></view>
			<view class="title">提现方式</view>

			<u-radio-group v-model="radiovalue" @change="radioChange" :wrap="true" active-color="#19BE6B">
				<view class="flex_bet_align type">
					<u-radio :name="1">
						<u-icon name="weixin-circle-fill" color="#00C900" size="40"></u-icon>
						<text>微信</text>
					</u-radio>
				</view>
				<view class="flex_bet_align type">
					<u-radio :name="3">
						<u-icon name="minus-square-fill" color="#077D85" size="40"></u-icon>
						<text>银行卡</text>
					</u-radio>
				</view>
			</u-radio-group>


			<!-- <view class="flex_bet_align type">
				<view>
					<u-icon name="zhifubao-circle-fill" color="#599FF7" size="32"></u-icon>
					<text>支付宝</text>
				</view>
				<view class="iconfont icon-xuanzhongyuandian"></view>
			</view> -->
			<!-- 	<view class="flex_bet_align type">
				<view>
					<u-icon name="minus-square-fill" color="#077D85" size="32"></u-icon>
					<text>银行卡</text>
				</view>
				<view class="iconfont icon-xuanzhong"></view>
			</view> -->

			<view class="block"></view>
			<view class="" v-if="withdrawal_type==3">
				<view class="flex_bet_align">
					<view class="title">选择银行卡</view>
					<navigator url="/personal/addCard" hover-class="none" class="add">+添加银行卡 </navigator>
				</view>
				<u-radio-group v-model="bank_id" @change="bankChange" :wrap="true" active-color="#19BE6B">
					<view class="flex_bet_align type" v-for="(item,index) in list" :key="index">
						<u-radio :name="item.id">
							<u-icon name="minus-square-fill" color="#077D85" size="40"></u-icon>
							<text>{{item.bank_name}}</text>
						</u-radio>
					</view>
				</u-radio-group>
			</view>
		</view>
		<view style="height:140rpx;"></view>
		<view class="btn" @click="submit">提交</view>
	</view>
</template>

<script>
	var _this, shak;
	export default {
		data() {
			return {
				wallet: {},
				withdrawal_money: "",
				maxlength: 10,
				radiovalue: 1,
				withdrawal_type: 1,
				list: [],
				bank_id: ''
			}
		},
		onShow(options) {
			_this = this
			_this.getdata()
			_this.getcard()
		},
		methods: {
			// 获取数据
			getdata() {
				_this.$api.get("returnbalance", {}).then(data => {
					console.log(Number(data.commission))
					console.log(parseInt(Number(data.commission)))
					data.commission = parseInt(Number(data.commission) * 100)
					_this.wallet = data
				});

			},

			getcard() {
				_this.$api.get("getbanklist").then(data => {
					console.log(data.data)
					_this.list = data.data
				});
			},

			radioChange(e) {
				console.log(e)
				_this.withdrawal_type = e
			},
			bankChange(e) {
				console.log(e)
				_this.bank_id = e
			},
			// 提交
			submit() {
				_this.click_shake(function() {
					let data = [{
						value: _this.withdrawal_money,
						type: 1,
						title: "请填写提现金额"
					}, {
						value: [_this.withdrawal_money, _this.wallet.withdrawaMinPrice],
						type: 8,
						title: "提现金额不能小于最小提现金额"
					}, {
						value: [_this.withdrawal_money, _this.wallet.withdrawalMaxPrice],
						type: 7,
						title: "提现金额不能大于最大提现金额"
					}]
					let info = {}
					info.withdrawal_money = _this.withdrawal_money
					info.withdrawal_type = _this.withdrawal_type
					if (_this.withdrawal_type == 3) {
						info.bank_id = _this.bank_id
					}
					console.log(info)

					_this.$api.post("withdrawalapply", info).then(data => {
						wx.showToast({
							title: "申请成功"
						})
						setTimeout(function() {
							wx.navigateBack({
								delta: 1
							})
						}, 500);
					});
					// if (_this.$plug.verify(data)) {

					// }
				})
			},
			// 防抖点击
			click_shake(fn) {
				if (!_this.shake) {
					fn && typeof fn === 'function' && fn()
					_this.shake = true
					setTimeout(function() {
						_this.shake = false
					}, 500)
				}
			},

			// checkNum(e) {
			// 	let value = e.detail.value;
			// 	console.log(value)
			// 	let dot = value.indexOf('.'); //包含小数点
			// 	let reg = /^[0-9]+$/; //正整数
			// 	if (dot > -1) {
			// 		this.maxlength = dot + 3; //长度是小数点后两位
			// 		if (value.length > dot + 3) {}
			// 	}
			// 	if (reg.test(value)) { //如果是正整数不包含小数点
			// 		this.maxlength = 10;
			// 	}
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.block {
		height: 10rpx;
		background-color: #F2F2F2;
	}

	.wrap {
		padding: 0 30rpx;

		.item {
			padding: 35rpx 0 40rpx;
			border-bottom: 1rpx solid #EEEEEE;

			.name,
			.count {
				font-size: 30rpx;
				color: #000000;

				text {
					font-size: 24rpx;
					color: #999999;
					margin-left: 15rpx;
				}
			}

			input {
				font-size: 30rpx;
				text-align: right;
			}
		}

		.title {
			font-size: 26rpx;
			font-weight: 500;
			color: #666666;
			line-height: 100rpx;
		}

		.add {
			font-size: 26rpx;
			font-weight: 500;
			color: #333333;
			line-height: 100rpx;
		}

		.type {
			padding: 32rpx 0;

			text {
				margin-left: 20rpx;
			}

			.iconfont {
				color: #8E8E8E;
				font-size: 30rpx;
			}

			.icon-xuanzhong {
				color: #38BE8C;
			}
		}
	}

	.btn {
		width: 680rpx;
		height: 90rpx;
		background: linear-gradient(86deg, #38be8c 0%, #05adbb 100%);
		border-radius: 45rpx;
		font-size: 34rpx;
		font-weight: 700;
		text-align: center;
		color: #ffffff;
		line-height: 90rpx;
		position: fixed;
		left: 28rpx;
		bottom: 46rpx;
	}

	/deep/.u-radio {
		width: 690rpx !important;
		display: flex;
		align-items: center;
		flex-direction: row-reverse;
		justify-content: space-between;
	}

	/deep/.u-radio__label {
		display: flex;
		align-items: center;
	}
</style>
